<template>
  <div id="kgo-context">    
 
     <div id="kgo-head">
       <head-nav></head-nav>
     </div>
     <div id="kgo-left">      
         <router-view name="left"></router-view>
     </div>
      <div id="kgo-body" :style="{width:kgoBodyWidth+'px',height: kgoBodyHeight+'px'}">
         <router-view/>
     </div>
  </div>
 
</template>

<script>
import HeadNav from './module/HeadNav'
export default {
   components: {
      HeadNav
    
  },
  created(){
    var that = this;
   
    if(KgoUtil.objIsNotNull(Cookies.get('isLogin'))&&(Cookies.get('isLogin')==true||Cookies.get('isLogin')=="true")&&KgoUtil.objIsNotNull(Cookies.get('userId'))){
      
       that.getCurrentUserInfo(Cookies.get('userId'));
       return;
    }
     KgoUtil.setState("rootUrl",this.$store.state.RootURL); 
     $.ajax({
        url: "./static/layerPage/login.html",
        type:"GET",
        async: true,
        dataType:'html',
        success: function(logodata){
            layer.open({
                title: '系统登录',
                area: ['100%', '100%'],
                type:1,
                closeBtn:0,
                content: logodata,
                end:function(){
                  //将用户新更新到系统
                  that.$store.commit('updateUserInfo', KgoUtil.getState("UserInfo"));
                  that.connectWebSocket();
                }
            });
        }
      });  
  },
  data(){
    return {
      kgoBodyWidth : document.body.clientWidth-240,
      kgoBodyHeight : document.body.clientHeight-80,
    } 
  },
  methods:{
    /**
     * 连接WebSocket
     */
    connectWebSocket:function(){
      wsLead.connectWS(this.$store.state.WsURL+"/websocket",this.$store.state.userInfo.id);
    },
    /**
     * 获取当前用户信息
     */
    getCurrentUserInfo:function(id){
            var user_info_url = this.$store.state.RootURL + "/user/id";
            var that = this;
            $.ajax({
                url: user_info_url,
                type:"get",
                async: true,
                dataType:'json',
                data:{id:id},
                success: function(data){
                  console.log("用户信息 ：" + JSON.stringify(data.data) );
                  that.$store.commit('updateUserInfo', data.data);
                  that.connectWebSocket();
                }
            });
    }

  }
 
}
</script>

<style lang="scss">
#kgo-context{
  height: 100%;
  width: 100%;
  background-color: $theme-color;
}
#kgo-head {
  position: absolute;
  top: 0;
  height:$whole-head-height;
  width: 100%;
  background-color: $theme-color;
  z-index: 199;
}
#kgo-left{
  width: $whole-left-nav-width ;
  height: 100%;
  position: absolute;
  top:0px;
  background-color:$theme-left-color;
  z-index: 299;
}
#kgo-body{
  position: fixed;
  top: $whole-head-height;
  background-color: $theme-background;
  left: 215px;
  padding-top: 10px;
  padding-left: 10px;
  padding-right: 15px;
  overflow:auto;
  overflow-x: hidden;
}

</style>
